﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Pyramid.Models;

namespace Pyramid.Controllers
{
	public class ConsumeItemController : BaseController
	{
		public ActionResult List()
		{
			return View(Db.ConsumeItems.ToList());
		}

		public ActionResult SelectList()
		{
			return View(Db.ConsumeItems.ToList());
		}

		public ActionResult Create()
		{
			var model = new ConsumeItem();
			return View("Edit", model);
		}

		public ActionResult Edit(int id)
		{
			var model = Db.ConsumeItems.Find(id);
			return View(model);
		}

		[HttpPost]
		public ActionResult Edit(ConsumeItem model)
		{
			if (model.Id == 0)
			{
				Db.ConsumeItems.Add(model);
			}
			else
			{
				Db.Entry(model).State = EntityState.Modified;
			}
			Db.SaveChanges();
			return JSuccess("操作成功", "tab_ccm_consumeitem");
		}

		public ActionResult Delete(int id)
		{
			var model = new ConsumeItem
			            {
				            Id = id
			            };
			Db.Entry(model).State = EntityState.Deleted;
			Db.SaveChanges();
			return JSuccess("操作成功", "tab_ccm_consumeitem");
		}
	}
}
